/*
 * Created by SharpDevelop.
 * User: David
 * Date: 2006-12-24
 * Time: 22:09
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;

using tools;

namespace Labb4.Pooman.Game
{
	/// <summary>
	/// Holds all the settings and properties of the game as the player sees it.
	/// </summary>
	public sealed class Properties
	{
		#region members
		
		/// <summary>
		/// The one instance
		/// </summary>
		private static Properties		m_Instance = new Properties();
		
		/// <summary>
		/// Property flags
		/// </summary>
		private int						m_Flags;
		/// <summary>
		/// The time cards are displayed on the table, before they're removed
		/// </summary>
		private int						m_DisplayTimeForWonCards;
		
		/// <summary>
		/// The path to the folder where this game was started
		/// </summary>
		private readonly string			m_StartPath;
		
		/// <summary>
		/// Constant for an unset flag, setting the flag to this value will clear it
		/// </summary>
		public const int				BLANK_FLAG = 0;
		/// <summary>
		/// Constant for the debug flag, or:ing in this value in the flag will force the game
		/// into debug mode
		/// </summary>
		public const int				DEBUG_FLAG = 1;
		/// <summary>
		/// Constant for the open cards flag, or:ing in this value in the flag will force the game
		/// to show the ai's cards
		/// </summary>
		public const int				OPEN_CARDS_FLAG = 2;
		/// <summary>
		/// Constant for the muted audio flag, or:ing in this value in the flag will force the game
		/// to mute (i.e. turn off) the audio
		/// </summary>
		public const int				MUTE_AUDIO_FLAG = 4;
		/// <summary>
		/// Constant for the tool tip flag, or:ing in this value in the flag will force the game
		/// to display tool tips whenever they are available
		/// </summary>
		public const int				TOOL_TIP_FLAG = 8;
		
		#endregion
		
		#region constructors
		
		/// <summary>
		/// Constructor, initializes members, sets the start path
		/// </summary>
		private Properties()
		{
			m_Flags = BLANK_FLAG;
			m_DisplayTimeForWonCards = 0;
			
			ListFileTool t = new ListFileTool();
			string startPath = t.GetDirectoryOfFile("dat");
			m_StartPath = startPath.Substring(0, startPath.Length - 3);
		}
		
		#endregion
		
		#region properties
		
		/// <summary>
		/// The one instance (get)
		/// </summary>
		public static Properties Instance
		{
			get
			{
				return m_Instance;
			}
		}
		
		/// <summary>
		/// The path to the directory this program was started from (get)
		/// </summary>
		public string StartPath
		{
			get
			{
				return m_StartPath;
			}
		}
		
		/// <summary>
		/// Determines if the game is in debug mode (set/get)
		/// </summary>
		public bool Debug
		{
			get
			{
				return ((m_Flags & DEBUG_FLAG) == DEBUG_FLAG);
			}
			
			set
			{
				if(value)
				{
					m_Flags |= DEBUG_FLAG;
				}
				else
				{
					if((m_Flags & DEBUG_FLAG) == DEBUG_FLAG)
					{
						m_Flags ^= DEBUG_FLAG;
					}
				}
			}
		}
		
		/// <summary>
		/// Determines if the ai players play with open cards or not (set/get)
		/// </summary>
		public bool OpenCards
		{
			get
			{
				return ((m_Flags & OPEN_CARDS_FLAG) == OPEN_CARDS_FLAG);
			}
			
			set
			{
				if(value)
				{
					m_Flags |= OPEN_CARDS_FLAG;
				}
				else
				{
					if((m_Flags & OPEN_CARDS_FLAG) == OPEN_CARDS_FLAG)
					{
						m_Flags ^= OPEN_CARDS_FLAG;
					}
				}
			}
		}
		
		/// <summary>
		/// Determines if the audio is muted or not (set/get)
		/// </summary>
		public bool MuteAudio
		{
			get
			{
				return ((m_Flags & MUTE_AUDIO_FLAG) == MUTE_AUDIO_FLAG);
			}
			
			set
			{
				if(value)
				{
					m_Flags |= MUTE_AUDIO_FLAG;
					//Labb4.Media.Sfx.FMODManager.Instance.Muted = true;
				}
				else
				{
					if((m_Flags & MUTE_AUDIO_FLAG) == MUTE_AUDIO_FLAG)
					{
						m_Flags ^= MUTE_AUDIO_FLAG;
						//Labb4.Media.Sfx.FMODManager.Instance.Muted = false;
					}
				}
			}
		}
		
		/// <summary>
		/// Determines if the tool tips should be displayed (set/get)
		/// </summary>
		public bool ToolTip
		{
			get
			{
				return ((m_Flags & TOOL_TIP_FLAG) == TOOL_TIP_FLAG);
			}
			
			set
			{
				if(value)
				{
					m_Flags |= TOOL_TIP_FLAG;
				}
				else
				{
					if((m_Flags & TOOL_TIP_FLAG) == TOOL_TIP_FLAG)
					{
						m_Flags ^= TOOL_TIP_FLAG;
					}
				}
			}
		}
		
		/// <summary>
		/// The flag containing references to all the boolean settings (set/get)
		/// </summary>
		public int Flags
		{
			get
			{
				return m_Flags;
			}
			
			set
			{
				m_Flags = value;
				
				if((m_Flags & MUTE_AUDIO_FLAG) == MUTE_AUDIO_FLAG)
				{
					Labb4.Media.Sfx.FMODManager.Instance.Muted = true;
				}
			}
		}
		
		/// <summary>
		/// The time cards are laying still on the table after a stick has ended. Unit is (ms) (set/get)
		/// </summary>
		public int DisplayTimeForWonCards
		{
			get
			{
				return m_DisplayTimeForWonCards;
			}
			
			set
			{
				m_DisplayTimeForWonCards = value;
			}
		}
		
		#endregion
	}
}
